package com.zhentao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.mapper.TbDoctorMapper;
import com.zhentao.pojo.TbDoctor;
import com.zhentao.service.TbDoctorService;
import com.zhentao.vo.Query;
import com.zhentao.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/doctor")
public class DoctorController {
    @Autowired
    private TbDoctorMapper doctorMapper;
    @Autowired
    private TbDoctorService doctorService;
    @RequestMapping("findPage1")
    public Result findPage1(@RequestBody Query query){
        Page<TbDoctor> page = doctorService.findPage(query);
       return Result.OK(page);
    }
    //查询医生信息


    //添加医生信息
    @RequestMapping("/addDoctor")
    public String addDoctor(@RequestBody TbDoctor doctor){
        int insert = doctorMapper.insert(doctor);
        return insert>0?"添加成功":"添加失败";
    }

    //删除医生信息
    @RequestMapping("/deleteDoctor")
    public String deleteDoctor(Integer id){
        int delete = doctorMapper.deleteById(id);
        return delete>0?"删除成功":"删除失败";
    }

//    //修改医生信息
//    @RequestMapping("/updateDoctor")
//    public String updateDoctor(TbDoctor doctor){
//        // 检查ID是否为空
//        if (doctor.getId() == null) {
//            return "修改失败：医生ID不能为空";
//        }
//        int update = doctorMapper.updateById(doctor);
//        return update>0?"修改成功":"修改失败";
//    }


    //修改医生信息
    @PostMapping("/updateDoctor")
    public String updateDoctor(@RequestBody TbDoctor doctor){
        if (doctor == null || doctor.getId() == null) {
            return "医生信息或ID不能为空";
        }
        int update = doctorMapper.updateById(doctor);
        return update>0?"修改成功":"修改失败";
    }

    //获取科室列表
    @RequestMapping("/Departments")
    public Result getDepartments(){
        return Result.OK(doctorMapper.getDepartments());
    }
}
